import React from 'react';
import weAjax from '../utils/ajax';

const api = 'http://bm.juzhen.net/register';

class TableUpdate extends React.Component {
    // constructor(props) {
    //     super(props);
    //     // {"Field":"id","Type":"int(11)","Collation":null,"Null":"NO","Key":"PRI","Default":null,
    //     // "Extra":"auto_increment","Privileges":"select,insert,update,references","Comment":"活动ID号"}
    //     // this.props.comments
    //     // this.props.dataItem

    // }

    update() {
        // weAjax({ url: api, method: 'post' }, {
        //     userid: this.state.userid,
        //     userpw: this.state.userpw,
        //     usertype: this.state.usertype,
        //     nickname: this.state.nickname
        // }, (data) => {
        //     console.log(data);
        // })
    }

    onSubmit(e) {
        e.preventDefault();
        this.onSubmit();
    }

    render() {

        let inputs = this.props.comments.map((commentItem, i) => {
            let type = 'text';
            if (commentItem.Type === 'timestamp' || commentItem.Type === 'datetime') {
                type = 'date';
            }
            if (commentItem.Key === 'PRI') {  // 主键不参与修改
                return <input disabled className="form-input" type={type} value={this.props.dataItem[commentItem.Field]} />;
            }
            return <input className="form-input" type={type} value={this.props.dataItem[commentItem.Field]} />
        })

        return (
            <div>
                <div className="form-form" >
                    <div className="form-title">{this.props.name}</div>
                    {inputs}
                    <button onClick={this.onSubmit} className='form-button'>修  改</button>
                </div>
            </div>
        );
    }
}

export default TableUpdate;